﻿namespace Away.IdentityServer.Core.Api;

public static class ApiScopeApi
{
    /// <summary>
    /// api作用域管理接口
    /// </summary>
    public static IEndpointRouteBuilder MapApiScopeApi(this IEndpointRouteBuilder endpoint)
    {
        endpoint.MapGet("/api/scope/list", List);
        endpoint.MapGet("/api/scope", Page);
        endpoint.MapPost("/api/scope", Save);
        endpoint.MapDelete("/api/scope", Remove);
        return endpoint;
    }

    /// <summary>
    /// 获取API作用域列表
    /// </summary>
    private static IResult List(IApiScopeService service)
    {
        var data = service.List();
        return ApiResult.Ok(data);
    }

    /// <summary>
    /// 查询API作用域分页列表
    /// </summary>
    private static IResult Page([AsParameters] ApiScopeSearch search, IApiScopeService service)
    {
        return service.Page(search);
    }

    /// <summary>
    /// 添加、编辑API作用域
    /// </summary>
    private static IResult Save([FromBody] ApiScope model, IApiScopeService service)
    {
        service.Save(model);
        return ApiResult.Ok();
    }

    /// <summary>
    /// 删除作用域
    /// </summary>
    private static IResult Remove([FromBody] List<int> ids, IApiScopeService service)
    {
        service.Remove(ids);
        return ApiResult.Ok();
    }
}